{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "4ae463ae-d4d0-4a52-bc85-18fd7cd00a92",
   "metadata": {
    "tags": []
   },
   "source": [
    "# hydrodata.stac.mini模块\n",
    "用于从minio中获取数据集范围"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "38009de2-ae5f-4677-894c-3230808a84f8",
   "metadata": {},
   "source": [
    "## 数据准备"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "1b7bab26-2709-4c55-bbb5-052590437791",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "from hydrodata.catalog.minio import ERA5LCatalog, GPMCatalog, GFSCatalog\n",
    "import geopandas as gpd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "4be5a3de-d94a-400e-9246-0e43bcf58bc5",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>geometry</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>MULTIPOLYGON (((122.44241 39.80139, 122.39342 ...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   id                                           geometry\n",
       "0   0  MULTIPOLYGON (((122.44241 39.80139, 122.39342 ..."
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aoi = gpd.read_file('basin.geojson')\n",
    "aoi"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a205aeb8-3de2-421b-8514-a7bf347a7bb1",
   "metadata": {},
   "source": [
    "## 获取era5数据清单"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "5aa2b0c3-291a-434e-8c69-b41a592201dd",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'wis': {'start_time': numpy.datetime64('2015-07-01T00:00:00'),\n",
       "  'end_time': numpy.datetime64('2021-12-31T23:00:00'),\n",
       "  'bbox': [115, 38, 136, 54]}}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "era5 = ERA5LCatalog()\n",
    "era5.datasets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "38fc4cc5-05f7-4a13-9820-5c320b23d6a7",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>dataset</th>\n",
       "      <th>start_time</th>\n",
       "      <th>end_time</th>\n",
       "      <th>geometry</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>era5-land</td>\n",
       "      <td>wis</td>\n",
       "      <td>2015-07-01T00:00:00</td>\n",
       "      <td>2021-12-31T23:00:00</td>\n",
       "      <td>POLYGON ((122.39342 39.81027, 122.31744 39.833...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          id dataset           start_time             end_time  \\\n",
       "0  era5-land     wis  2015-07-01T00:00:00  2021-12-31T23:00:00   \n",
       "\n",
       "                                            geometry  \n",
       "0  POLYGON ((122.39342 39.81027, 122.31744 39.833...  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "e = era5.search(aoi=aoi)\n",
    "e"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1cdb1a8e-7366-4bbf-9c88-136de9b65739",
   "metadata": {},
   "source": [
    "## 获取gpm数据清单"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "0de7345f-d6c7-47cd-adab-c7d3d45e0cc9",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'wis': [{'time_resolution': '30 minutes',\n",
       "   'start_time': numpy.datetime64('2016-01-01T00:00:00.000000000'),\n",
       "   'end_time': numpy.datetime64('2023-10-11T08:30:00.000000000'),\n",
       "   'bbox': [73, 3, 136, 54]},\n",
       "  {'time_resolution': '1 day',\n",
       "   'start_time': numpy.datetime64('2000-06-01T00:00:00.000000000'),\n",
       "   'end_time': numpy.datetime64('2023-09-26T23:59:59.000000000'),\n",
       "   'bbox': [73, 3, 136, 54]}],\n",
       " 'camels': [{'time_resolution': '30 minutes',\n",
       "   'start_time': numpy.datetime64('2022-01-01T00:00:00.000000000'),\n",
       "   'end_time': numpy.datetime64('2023-08-31T23:30:00.000000000'),\n",
       "   'bbox': [-125, 25, -66, 50]},\n",
       "  {'time_resolution': '1 day',\n",
       "   'start_time': numpy.datetime64('2000-06-01T00:00:00.000000000'),\n",
       "   'end_time': numpy.datetime64('2014-12-31T23:59:59.000000000'),\n",
       "   'bbox': [-125, 25, -66, 50]}]}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gpm = GPMCatalog()\n",
    "gpm.datasets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "5c384715-4432-423c-acdf-c2f5d00a3bda",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>dataset</th>\n",
       "      <th>time_resolution</th>\n",
       "      <th>start_time</th>\n",
       "      <th>end_time</th>\n",
       "      <th>geometry</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>gpm-imerg-early</td>\n",
       "      <td>wis</td>\n",
       "      <td>30 minutes</td>\n",
       "      <td>2016-01-01T00:00:00.000000000</td>\n",
       "      <td>2023-10-11T08:30:00.000000000</td>\n",
       "      <td>POLYGON ((122.39342 39.81027, 122.31744 39.833...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>gpm-imerg-early</td>\n",
       "      <td>wis</td>\n",
       "      <td>1 day</td>\n",
       "      <td>2000-06-01T00:00:00.000000000</td>\n",
       "      <td>2023-09-26T23:59:59.000000000</td>\n",
       "      <td>POLYGON ((122.39342 39.81027, 122.31744 39.833...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                id dataset time_resolution                     start_time  \\\n",
       "0  gpm-imerg-early     wis      30 minutes  2016-01-01T00:00:00.000000000   \n",
       "0  gpm-imerg-early     wis           1 day  2000-06-01T00:00:00.000000000   \n",
       "\n",
       "                        end_time  \\\n",
       "0  2023-10-11T08:30:00.000000000   \n",
       "0  2023-09-26T23:59:59.000000000   \n",
       "\n",
       "                                            geometry  \n",
       "0  POLYGON ((122.39342 39.81027, 122.31744 39.833...  \n",
       "0  POLYGON ((122.39342 39.81027, 122.31744 39.833...  "
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "g = gpm.search(aoi=aoi)\n",
    "g"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c090ad8e-a967-4c09-b115-e290b18cc44d",
   "metadata": {},
   "source": [
    "## 获取gfs数据清单"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "a12fb26c-633b-419f-9e7c-d3ab5a0d3579",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'wis': [{'start': '2016-07-10T00',\n",
       "   'end': '2022-08-31T18',\n",
       "   'bbox': [115, 38, 136, 54]},\n",
       "  {'start': '2022-09-01T00',\n",
       "   'end': '2023-10-11T06',\n",
       "   'bbox': [73, 3, 136, 54]}]}"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gfs = GFSCatalog('tp')\n",
    "gfs.datasets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "2f362458-3458-481a-a9b5-fb964a844332",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>dataset</th>\n",
       "      <th>start_time</th>\n",
       "      <th>end_time</th>\n",
       "      <th>geometry</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>gfs_atmos.tp</td>\n",
       "      <td>wis</td>\n",
       "      <td>2016-07-10T00</td>\n",
       "      <td>2022-08-31T18</td>\n",
       "      <td>POLYGON ((122.39342 39.81027, 122.31744 39.833...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>gfs_atmos.tp</td>\n",
       "      <td>wis</td>\n",
       "      <td>2022-09-01T00</td>\n",
       "      <td>2023-10-11T06</td>\n",
       "      <td>POLYGON ((122.39342 39.81027, 122.31744 39.833...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             id dataset     start_time       end_time  \\\n",
       "0  gfs_atmos.tp     wis  2016-07-10T00  2022-08-31T18   \n",
       "0  gfs_atmos.tp     wis  2022-09-01T00  2023-10-11T06   \n",
       "\n",
       "                                            geometry  \n",
       "0  POLYGON ((122.39342 39.81027, 122.31744 39.833...  \n",
       "0  POLYGON ((122.39342 39.81027, 122.31744 39.833...  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f = gfs.search(aoi=aoi)\n",
    "f"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (dev-env)",
   "language": "python",
   "name": "dev-env"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
